#pragma once

#include "messages.hpp"
#include "model/DHT11.h"
#include "model/OneWire.hpp"

namespace actor {

struct DHT : rl::Actor<3> {
  using Parent = rl::Actor<3>;
  using Model = model::OneWire<5>;

  enum class Substate {
    none,
    hs_keep_high,
    hs_wait_low,
  };

  void initialize() override;
  void advance_init() override;
  void on_timer();
  void on_edge();

  void on_request(message::RequestHT &);

private:
  void handshake_continue();
  void handshake_wait_low();

  Model model;
  Substate substate = Substate::none;
  uint8_t wire_value = 0;
};

} // namespace actor
